package cn.enjoy.design.structure.proxy.listener.base;

import cn.enjoy.design.structure.proxy.Enums.FlowTypeEnum;
import cn.enjoy.design.structure.proxy.entity.FlowFormNotification;
import cn.enjoy.design.structure.proxy.event.FlowEvent;
import cn.enjoy.design.structure.proxy.event.base.BaseSubmitEvent;
import cn.enjoy.design.structure.proxy.listener.FlowStateListener;
import cn.enjoy.design.structure.proxy.mapper.FlowFormNotificationMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author K
 * @date 2021-07-18 18:34
 */
@Service
@AllArgsConstructor
@Slf4j
public class BaseFlowFormNoticeListener implements FlowStateListener<FlowEvent> {

    private FlowFormNotificationMapper flowFormNotificationMapper;


    @Override
    public void handler(FlowEvent flowEvent) {
        if (flowEvent.getType() == FlowTypeEnum.BASE) {
            if (flowEvent instanceof BaseSubmitEvent) {
                insertNotification(((BaseSubmitEvent) flowEvent).getFlowFormId(), "发起");
            }
//            else if (flowEvent instanceof BaseHandledEvent) {
//                insertNotification(((BaseHandledEvent) event).getFlowFormId(), "已处理");
//            } else if (flowEvent instanceof BaseAcceptorEvent) {
//                insertNotification(((BaseAcceptorEvent) event).getFlowFormId(), "受理中");
//            } else if (flowEvent instanceof BaseCloseEvent) {
//                insertNotification(((BaseCloseEvent) event).getFlowFormId(), "完成");
//            }
        }
    }

    private void insertNotification(Long flowFormId, String operation) {
        FlowFormNotification flowFormNotification = new FlowFormNotification();
        flowFormNotification.setFlowFormId(flowFormId);
//        flowFormNotification.setUserId();
        flowFormNotification.setNotificationType(1);

        flowFormNotificationMapper.insert(flowFormNotification);
    }


}
